package com.m.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 功能: <br/>
 *
 * @author miracle
 */
@Component
@Aspect
public class ControllerExceptionLog {

    @Pointcut("execution(* com.m.controller..*(..))")
    public void recordLog() {}

    @AfterThrowing(value = "recordLog()", throwing = "exception")
    public void doAfterThrowException(JoinPoint joinPoint, Throwable exception) {
        Class<?> aClass = joinPoint.getTarget().getClass();
        String method = joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName();
        Logger logger = LoggerFactory.getLogger(aClass);
        logger.error(method + ": ", exception);
    }
}
